package com.gitee.tianchaohongyu;

import com.gitee.tianchaohongyu.service.RemoteServer;
import com.gitee.tianchaohongyu.utils.Arguments;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.Random;

@Slf4j
@SpringBootApplication
public class Remote2Application {

    private static int port;
    private static String password;

    public static void main(String[] args) {
        Arguments arguments = new Arguments();
        arguments.addArg("端口", "p", "port");
        arguments.addArg("密码", "a", "password");
        arguments.parse(args);
        port = arguments.getInt("port", 999);
        password = arguments.getString("password", String.valueOf(100000 + new Random().nextInt(900000)));

        SpringApplication.run(Remote2Application.class, args);
    }

    @Bean(initMethod = "start")
    public RemoteServer remoteServer() {
        log.info("服务器端口:{},密码:{}", port, password);
        return new RemoteServer(port, password);
    }

}
